package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-20 15:14
 **/
public class LeetCode717 {

    //官方版本
    public boolean isOneBitCharacter(int[] bits) {
        int n = bits.length, i = 0;
        while (i < n - 1) {
            i += bits[i] + 1;
        }
        return i == n - 1;
    }

    //我的版本
    /*public boolean isOneBitCharacter(int[] bits) {
        int n = bits.length;
        if (bits[n - 1] != 0) {
            return false;
        }

        for (int i = 0; i < n - 1;) {
            if (bits[i] == 0) {
                ++i;
                continue;
            }

            if (i == n - 2) {
                return false;
            } else {
                i += 2;
            }
        }

        return true;
    }*/

}
